package com.hsfw.pmbasicdata.controller;

import com.hsfw.dbmodule.utils.BaseResponse;
import com.hsfw.pmbasicdata.service.BasicDataService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "基础数据模块")
@RestController
@RequestMapping("/basic-data/")
public class BasicDataController {
    @Autowired
    BasicDataService basicDataService;

    @ApiOperation(value = "树形菜单")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "数据正常"),
            @ApiResponse(code = 404, message = "程序正常，但是没有数据")})
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "parentID", paramType = "query", value = "当前节点ID", dataType = "string", defaultValue = "-1", required = true),
                    @ApiImplicitParam(name = "ifAllNode", paramType = "query", value = "是否获取所有子节点", dataType = "string", defaultValue = "YES", required = true)
            }
    )
    @PostMapping("tree-menu")
    public BaseResponse getTreeMenuByParentId(@RequestParam(value = "parentID") String parentID,
                                              @RequestParam(value = "ifAllNode") String ifAllNode,
                                              @RequestParam(value = "treeType") String treeType) {
        return BaseResponse.buildResponse().setObj(basicDataService.getTreeMenuByNodeID(parentID, ifAllNode, treeType)).build();
    }


    @ApiOperation(value = "表格表头数据")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "数据正常"),
            @ApiResponse(code = 404, message = "程序正常，但是没有数据")})
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "tableName", paramType = "query", value = "表格实体名", dataType = "string", defaultValue = "dataaircraft", required = true),
            }
    )
    @PostMapping("table-header")
    public BaseResponse getTreeTableHeaderByTableName(@RequestParam(value = "tableName") String tableName) {
        return BaseResponse.buildResponse().setObj(basicDataService.getTableNameList(tableName)).build();
    }

    @ApiOperation(value = "表格数据")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "数据正常"),
            @ApiResponse(code = 404, message = "程序正常，但是没有数据")})
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "tableName", paramType = "query", value = "表格实体名", dataType = "string", defaultValue = "dataaircraft", required = true),
                    @ApiImplicitParam(name = "parentId", paramType = "query", value = "父类id（多个以逗号分隔）", dataType = "string", defaultValue = "16,17", required = true),
                    @ApiImplicitParam(name = "startPage", paramType = "query", value = "开始页", dataType = "int", defaultValue = "1", required = true),
                    @ApiImplicitParam(name = "pagNum", paramType = "query", value = "每页条数", dataType = "int", defaultValue = "30", required = true),
            }
    )
    @PostMapping("table-info")
    public BaseResponse getTableInfoByParentId(@RequestParam(value = "treeType") String treeType,
                                               @RequestParam(value = "tableName") String tableName,
                                               @RequestParam(value = "parentId") String parentId,
                                               @RequestParam(value = "startPage") int startPage,
                                               @RequestParam(value = "pageNum") int pagNum) {
        return BaseResponse.buildResponse().setObj(basicDataService.getTableInfoListByParentId(treeType, tableName,
                parentId, startPage, pagNum)).build();
    }

    @ApiOperation(value = "实体详情信息")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "数据正常"),
            @ApiResponse(code = 404, message = "程序正常，但是没有数据")})
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "guid", paramType = "query", value = "当前节点ID", dataType = "string", defaultValue = "hsfw-dataaircraft-000000000003", required = true),
                    @ApiImplicitParam(name = "tableName", paramType = "query", value = "节点类型", dataType = "string", defaultValue = "dataaircraft", required = true)
            }
    )
    @PostMapping("entity-info")
    public BaseResponse getEntityInfoById(@RequestParam(value = "guid") String guid,
                                              @RequestParam(value = "tableName") String tableName) {
        return BaseResponse.buildResponse().setObj(basicDataService.getEntityInfoById(guid, tableName)).build();
    }
}
